/* 
 *
 * Persistence4J - Simple library for data persistence using java
 * Copyright (c) 2010, Avdhesh yadav.
 * http://www.avdheshyadav.com
 * Contact: avdhesh.yadav@gmail.com
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */

package com.avdy.p4j.jdbc;

import java.util.Properties;


/**
 * This is immutable object so it can be shared without any problem in the system.
 * 
 * @author Avdhesh yadav
 */
public class PersistenceConfig
{
	/** */
	private Properties mProps;
	
	private static final String mContainerName = "persistence";
	
	
	/**
	 * 
	 * @param fileReader PropertyFileReader
	 */
	public PersistenceConfig(Properties props)
	{
		mProps = props;
	}
	

	/**
	 * 
	 * @return String
	 */
	public String getXaApiProvider()
	{
		return mProps.getProperty(mContainerName+".xaprovider");
	}
	
	/**
	 * 
	 * @return String
	 */
	public String getDbmss()
	{
		return mProps.getProperty(mContainerName + ".dbmss");
	}
	
	
	/**
	 * @param dbms  String
	 * 
	 * @return String
	 */
	public String getDatabaseDriver(String dbms)
	{
		return mProps.getProperty(mContainerName+".dbms."+ dbms+ ".driver");
	}
	
	
	/**
	 * 
	 * @param dbms  String
	 * 
	 * @return  String
	 */
	public String getHostName(String dbms)
	{
		return mProps.getProperty(mContainerName+".dbms." + dbms + ".hostname","localhost");
	}
	
	/**
	 * 
	 * @param dbms  String
	 * 
	 * @return  int
	 */
	public int getDataBasePort(String dbms)
	{
		return Integer.parseInt(mProps.getProperty(mContainerName+".dbms." + dbms + ".port"));
	}

	
	/**
	 * 
	 * @param dbms String
	 * 
	 * @return String
	 */
	public String getUserName(String dbms)
	{
		return mProps.getProperty(mContainerName+".dbms." + dbms + ".username","root");
	}
	
	
	/**
	 * 
	 * @param dbms String
	 * 
	 * @return String
	 */
	public String getPassword(String dbms)
	{
		return mProps.getProperty(mContainerName+".dbms." + dbms + ".password","");
	}
	
	
	/**
	 * @param dbms String
	 * 
	 * @return int
	 */
	public int getMinPool(String dbms)
	{
		return  Integer.parseInt(mProps.getProperty(mContainerName+".dbms." + dbms + ".minpool","10"));
	}
	
	
	/**
	 * @param dbms String
	 * 
	 * @return int
	 */
	public int getMaxPool(String dbms)
	{
		return  Integer.parseInt(mProps.getProperty(mContainerName+".dbms." + dbms + ".maxpool","30"));
	}
	
	
	/**
	 * @param dbms String
	 * @return String
	 */
	public String getXaDataSourceClassName(String dbms)
	{
		return mProps.getProperty(mContainerName+".dbms." + dbms + ".XaDataSourceClassName");
	}
}